import java.util.Scanner;

/**
 * @author gao
 * @date 2025/6/9 13:24
 */

public class Solution {
    public int jewelleryValue(int[][] frame) {
        // 获取框架的行数和列数
        int m = frame.length;
        int n = frame[0].length;

        // 创建一个二维数组dp，用于存储每个位置的最大珠宝价值
        int[][] dp = new int[m + 1][n + 1];

        // 遍历框架的每个位置
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= n; j++) {
                // 当前位置的最大珠宝价值等于当前位置的珠宝价值加上当前位置左边或上边的最大珠宝价值
                dp[i][j] = Math.max(dp[i][j - 1], dp[i - 1][j]) + frame[i - 1][j - 1];
            }
        }
        // 返回框架右下角的最大珠宝价值
        return dp[m][n];
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int m = in.nextInt();
            int n = in.nextInt();

            int[][] frame = new int[m][n];
            for (int i = 0; i < m; i++) {
                for (int j = 0; j < n; j++) {
                    frame[i][j] = in.nextInt();
                }
            }

            Solution solution = new Solution();
            System.out.println(solution.jewelleryValue(frame));
        }
    }
}